<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>login</title>
    <script src='../day14/jquery.js'></script>
</head>
<body>
    用户名：<input type="text" placeholder="Enter your username" />
    密码：<input type="password" placeholder="Enter your Password"/>
    <span class="submit" onclick="login()">登录</span>
</body>
<script>
    var baseUrl = 'http://47.93.206.13:8002'
    //登录
    function login() {
        //获取用户名和密码，并且保存到form对象中
        var form = {
            username:$('input[type="text"]').val(),
            password:$('input[type="password"]').val()
        }
        $.ajaxSetup({
            headers:{
                'content-type': 'application/json'
            }
        })
        //异步交互
        $.ajax({
            type:'post',
            url:baseUrl+'/user/login',
            data:form,
            success: function(data) {
                if(data.status === 200){
                    alert(data.message)
                    location.assign('./ajax.html')
                }else {
                    alert(data.message)
                }
            }
        })
        
    }
</script>
</html>